$(function () {
    //初始化菜单栏的数据
    $.post(ctx + "collage/getAllCollage", {}, function (r) {
        if (r.code === 0) {
            var data = r.msg;
            $('#collageTree').jstree({
                "core": {
                    'data': data.children,
                    'multiple': false
                },
                "state": {
                    "disabled": true
                },
                "checkbox": {
                    "three_state": false
                },
                "plugins": ["wholerow", "checkbox"]
            });
        } else {
            $JuXue.n_danger(r.msg);
        }
        init_collage_edit_data();
    });
})
function init_collage_edit_data() {
    var selected = $("#collageTable").bootstrapTreeTable("getSelections");
    var selected_length = selected.length;
    if (!selected_length) {$JuXue.n_warning('请勾选需要修改的高校或专业！');return;}
    if (selected_length > 1) {$JuXue.n_warning('一次只能修改一个高校或专业！');return;}

    var collageId = selected[0].id;
    $.post(ctx + "collage/getCollageInfo", {"collageId": collageId}, function (r) {
        if (r.code === 0) {
            var $CollageTree = $('#collageTree');
            var collage = r.msg;
            if(collage.parentId === 0){
                 $("input:radio[value='0']").trigger("click");
            }else {
                $("input:radio[value='1']").trigger("click");
            }
             $('#collageName').val(collage.collageName);
             $('#collageId').val(collage.collageId);
             $("#collageCode").val(collage.collageCode);

             $("#collageType").val(collage.collageType);
            $("#collageEdu").val(collage.collageEdu);

            $CollageTree.jstree('select_node', collage.parentId, true);
            $CollageTree.jstree('disable_node', collage.collageId);
        } else {
            $JuXue.n_danger(r.msg);
        }
    });
}

/**
 * 修改
 * **/
function editCollageInfo() {
    var ref = $('#collageTree').jstree(true);
    var arrayList = ref.get_checked();
    if(arrayList.length<=0){
        $("[name='parentId']").val(0);
    }else{
        $("[name='parentId']").val(ref.get_checked()[0]);
    }
    var form_data = $("#collage-update-form").serialize();

    $.post(ctx + "collage/updateCollage", form_data, function (r) {
        if (r.code === 0) {
            $JuXue.n_success(r.msg);
            $("#sale-modal").modal("hide");
            CollageRefresh();
        } else $JuXue.n_danger(r.msg);
    });
}